package com.asset.dispoal.verdict.service;

import com.asset.dispoal.verdict.api.JudgmentBookService;
import com.asset.dispoal.verdict.dto.request.CreateOrEditItemRequest;
import com.asset.dispoal.verdict.dto.request.CreateOrEditRequest;
import com.asset.dispoal.verdict.dto.request.JudgmentBookRequest;
import com.asset.dispoal.verdict.dto.request.JudgmentItemRequest;
import com.asset.dispoal.verdict.dto.response.JudgmentBookResponse;
import com.asset.dispoal.verdict.dto.response.JudgmentItemResponse;
import com.asset.dispoal.verdict.service.common.DeleteJudgmentCommand;
import com.asset.dispoal.verdict.service.common.DeleteJudgmentItemCommand;
import com.asset.dispoal.verdict.service.common.EditOrCreateCommand;
import com.asset.dispoal.verdict.service.common.EditOrCreateItemCommand;
import com.asset.dispoal.verdict.service.common.GetExtractParamCommand;
import com.asset.dispoal.verdict.service.common.QueryJudgmentCommand;
import com.asset.dispoal.verdict.service.common.QueryJudgmentItemCommand;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.util.CollectionUtils;
import tech.mhuang.pacebox.springboot.protocol.Result;
import tech.mhuang.pacebox.springboot.protocol.data.PageVO;

/**
 * @description:
 * @author: yf
 * @date: 2022-09-06
 */
@Service
public class GbJudgmentBookServiceImpl implements JudgmentBookService {
    @Autowired
    private QueryJudgmentCommand queryJudgmentCommand;
    @Autowired
    private EditOrCreateCommand editOrCreateCommand;
    @Autowired
    private DeleteJudgmentCommand deleteJudgmentCommand;
    @Autowired
    private QueryJudgmentItemCommand queryJudgmentItemCommand;
    @Autowired
    private EditOrCreateItemCommand editOrCreateItemCommand;
    @Autowired
    private DeleteJudgmentItemCommand deleteJudgmentItemCommand;
    @Autowired
    private GetExtractParamCommand getExtractParamCommand;

    @Override
    public Result<PageVO<JudgmentBookResponse>> findJudgmentBook(JudgmentBookRequest request) {
        return queryJudgmentCommand.execute(request);
    }

    @Override
    public Result editOrCreate(CreateOrEditRequest request) {
        return editOrCreateCommand.execute(request);
    }

    @Override
    public Result deleteBookById(String judgmentId) {
        return deleteJudgmentCommand.execute(judgmentId);
    }

    @Override
    public Result<PageVO<JudgmentItemResponse>> queryJudgmentById(JudgmentItemRequest request) {
        return queryJudgmentItemCommand.execute(request);
    }

    @Override
    public Result<JudgmentItemResponse> queryItemById(String itemId) {
        JudgmentItemRequest request = new JudgmentItemRequest();
        request.setId(itemId);
        Result<PageVO<JudgmentItemResponse>> result = queryJudgmentItemCommand.execute(request);
        if (!CollectionUtils.isEmpty(result.getData().getResult())) {
            return Result.ok(result.getData().getResult().get(0));
        }
        return Result.ok(new JudgmentItemResponse());
    }

    @Override
    public Result createOrEditBookItem(CreateOrEditItemRequest request) {
        return editOrCreateItemCommand.execute(request);
    }

    @Override
    public Result deleteItemById(String itemId) {
        return deleteJudgmentItemCommand.execute(itemId);
    }

    @Override
    public Result getExtractParam(String bookId) {
        return getExtractParamCommand.execute(bookId);
    }
}
